package com.ruoyi.amuse.announcements.controller;


import com.ruoyi.amuse.announcements.domain.ClubAnnouncements;
import com.ruoyi.amuse.announcements.service.IClubAnnouncementsService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 发布公告Controller
 * 
 * @author juwujie
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/announcements/announcements")
public class ClubAnnouncementsController extends BaseController
{
    @Autowired
    private IClubAnnouncementsService clubAnnouncementsService;

    /**
     * 查询发布公告列表
     */
    @RequiresPermissions("announcements:announcements:list")
    @GetMapping("/list")
    public TableDataInfo list(ClubAnnouncements clubAnnouncements)
    {
        startPage();
        List<ClubAnnouncements> list = clubAnnouncementsService.selectClubAnnouncementsList(clubAnnouncements);
        return getDataTable(list);
    }

    /**
     * 导出发布公告列表
     */
    @RequiresPermissions("announcements:announcements:export")
    @Log(title = "发布公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClubAnnouncements clubAnnouncements)
    {
        List<ClubAnnouncements> list = clubAnnouncementsService.selectClubAnnouncementsList(clubAnnouncements);
        ExcelUtil<ClubAnnouncements> util = new ExcelUtil<ClubAnnouncements>(ClubAnnouncements.class);
        util.exportExcel(response, list, "发布公告数据");
    }

    /**
     * 获取发布公告详细信息
     */
    @RequiresPermissions("announcements:announcements:query")
    @GetMapping(value = "/{announcementId}")
    public AjaxResult getInfo(@PathVariable("announcementId") Long announcementId)
    {
        return success(clubAnnouncementsService.selectClubAnnouncementsByAnnouncementId(announcementId));
    }

    /**
     * 新增发布公告
     */
    @RequiresPermissions("announcements:announcements:add")
    @Log(title = "发布公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClubAnnouncements clubAnnouncements)
    {
        return toAjax(clubAnnouncementsService.insertClubAnnouncements(clubAnnouncements));
    }

    /**
     * 修改发布公告
     */
    @RequiresPermissions("announcements:announcements:edit")
    @Log(title = "发布公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClubAnnouncements clubAnnouncements)
    {
        return toAjax(clubAnnouncementsService.updateClubAnnouncements(clubAnnouncements));
    }

    /**
     * 删除发布公告
     */
    @RequiresPermissions("announcements:announcements:remove")
    @Log(title = "发布公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{announcementIds}")
    public AjaxResult remove(@PathVariable Long[] announcementIds)
    {
        return toAjax(clubAnnouncementsService.deleteClubAnnouncementsByAnnouncementIds(announcementIds));
    }
}
